package com.gec.system.controller;

import com.gec.model.entity.SysCourse;
import com.gec.system.service.SysCourseService;
import com.gec.system.service.SysDevicesService;
import com.gec.system.service.SysUserService;
import com.gec.system.util.Result;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import net.bytebuddy.asm.Advice;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @ahthor: lxj
 * @date: 2024/3/12 13:39
 * @title:
 **/

@Api(tags = "数据管理控制器")
@RestController
@RequestMapping("/admin/system/sysDashboard")
public class SysDashboardController {

    @Autowired
    private SysCourseService sysCourseService;

    @Autowired
    private SysUserService sysUserService;

    @Autowired
    private SysDevicesService sysDevicesService;

    //    获取所有的课程数量
    @ApiOperation("获取所有的课程数量")
    @GetMapping("/selectCourseCount")
    public Result selectCourseCount() {

        int count = this.sysCourseService.count();
        return Result.ok(count);
    }

    //    获取所有的用户数量
    @ApiOperation("获取所有的用户数量")
    @GetMapping("/selectUserCount")
    public Result selectUserCount() {

        int count = this.sysUserService.count();
        return Result.ok(count);
    }

    //    获取所有的器材数量
    @ApiOperation("获取所有的器材数量")
    @GetMapping("/selectDevicesCount")
    public Result selectDevicesCount() {

        int count = this.sysDevicesService.count();
        return Result.ok(count);
    }

    //获取每个课程的当前报名人数
    @ApiOperation("获取课程名字和报名人数")
    @GetMapping("/getCourseData")
    public Result getCourseData() {

        List<SysCourse> list2 = this.sysCourseService.list();

        List<Map<String, Object>> list = new ArrayList<>();
        for (SysCourse course : list2) {
            Map<String, Object> map = new HashMap<String, Object>();
            map.put("name", course.getName());
            map.put("value", course.getAttendCount());
            list.add(map);
        }
        return Result.ok(list);
    }


}
